package felix.rule.module.flow;

import felix.rule.api.*;
import felix.rule.api.util.TNodeUtils;
import felix.rule.data.msg.EngineMsg;
import felix.rule.data.plugin.ComponentType;
import lombok.extern.slf4j.Slf4j;

@Slf4j
@RuleNode(
        type = ComponentType.ACTION,
        name = "acknowledge",
        configClazz = EmptyNodeConfiguration.class,
        nodeDescription = "Acknowledges the incoming message",
        nodeDetails = "After acknowledgement, the message is pushed to related rule nodes. Useful if you don't care what happens to this message next.",
        uiResources = {"static/rulenode/rulenode-core-config.js"},
        configDirective = "nodeEmptyConfig"
)
public class TAckNode implements TNode {

    EmptyNodeConfiguration config;

    @Override
    public void init(TContext ctx, TNodeConfiguration configuration) throws TNodeException {
        this.config = TNodeUtils.convert(configuration, EmptyNodeConfiguration.class);
    }

    @Override
    public void onMsg(TContext ctx, EngineMsg msg) {
        ctx.ack(msg);
        log.info("ack verion [{}] msg: {}", config.getVersion(), msg);
        ctx.tellSuccess(msg);
    }

    @Override
    public void destroy() {
    }
}
